package com.lytxmd.boxtest.utils;

import android.content.Context;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.TimePickerView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2016/12/20.
 */
public class PickerUtil {

    private PickerUtil(){}

    /**
     * 时间选择控件
     * @param context   上下文
     * @param listener  回调事件
     */
    public static void openTimePicker(Context context, TimePickerView.OnTimeSelectListener listener){
        TimePickerView timePickerView = new TimePickerView(context, TimePickerView.Type.YEAR_MONTH_DAY);
        timePickerView.setCyclic(false);
        timePickerView.setCancelable(true);
        //控制时间范围
        Calendar calendar = Calendar.getInstance();
        timePickerView.setRange(calendar.get(Calendar.YEAR) - 2, calendar.get(Calendar.YEAR) + 2);//要在setTime 之前才有效果哦
        timePickerView.setTime(new Date());
        //时间选择回调
        timePickerView.setOnTimeSelectListener(listener);
        timePickerView.show();
    }

    public static void pickerHourMins(Context context, TimePickerView.OnTimeSelectListener listener){
        TimePickerView timePickerView = new TimePickerView(context, TimePickerView.Type.HOURS_MINS);
        timePickerView.setCyclic(false);
        timePickerView.setCancelable(true);
        //控制时间范围
        Calendar calendar = Calendar.getInstance();
        //timePickerView.setRange(calendar.get(Calendar.YEAR) - 2, calendar.get(Calendar.YEAR) + 2);//要在setTime 之前才有效果哦
        timePickerView.setTime(new Date());
        //时间选择回调
        timePickerView.setOnTimeSelectListener(listener);
        timePickerView.show();
    }

    /**
     * 一级联动
     * @param context
     * @param resource
     * @param listener
     */
    public static void openSingleLinkagePicker(Context context, ArrayList resource, OptionsPickerView.OnOptionsSelectListener listener) {
        OptionsPickerView singleLinkagePicker = new OptionsPickerView(context);
        singleLinkagePicker.setPicker(resource);
        singleLinkagePicker.setCyclic(false);  //是否循环滚动
        singleLinkagePicker.setCancelable(true);
        singleLinkagePicker.setOnoptionsSelectListener(listener);
        singleLinkagePicker.show();
    }

}
